package com.hdoit.ares.web.weixin;

import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;

import com.tennetcn.common.selfcommon.message.wechat.Button;
import com.tennetcn.common.selfcommon.message.wechat.ComplexButton;
import com.tennetcn.common.selfcommon.message.wechat.Menu;
import com.tennetcn.common.selfcommon.message.wechat.ViewButton;
import com.tennetcn.common.utils.JsonUtils;

public class WxMenuCreateTest01 {
	//@Test
	public void createMenu(){
		WxMpService wxService = new WxMpServiceImpl(); 
		wxService.setWxMpConfigStorage(getConfig());
		
		String appId=wxService.getWxMpConfigStorage().getAppId();
		String menuJson=getMenu(appId);	
		
		System.out.println(menuJson);
		
		try {
			String menuId=wxService.getMenuService().menuCreate(menuJson);
			System.out.println(menuId);
		} catch (Exception e) {
			
		}
	}
	
	private String getMenu(String appId){
		
		
		ViewButton exclusiveService = new ViewButton();
		exclusiveService.setName("专属服务");
		exclusiveService.setType("view");
		exclusiveService.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxbd722b3620a78c59&redirect_uri=http://www.putiyoli.net/goldsinsweb/home/index.html&response_type=code&scope=snsapi_base#wechat_redirect");
		
		
		ViewButton myCodeButton = new ViewButton();
		myCodeButton.setName("我的邀请码");
		String discountViewUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxbd722b3620a78c59&redirect_uri=http://www.putiyoli.net/goldsinsweb/home/customer/initMyInviter.html&response_type=code&scope=snsapi_base#wechat_redirect";
		myCodeButton.setType("view");
		myCodeButton.setUrl(discountViewUrl);
		
		
		
		ComplexButton imSharedButton = new ComplexButton();
		imSharedButton.setName("我要分享");
		imSharedButton.setSub_button(new Button[] {myCodeButton});
		
		
		ViewButton personCenter = new ViewButton();
		personCenter.setName("我的中心");
		String personCenterViewUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxbd722b3620a78c59&redirect_uri=http://www.putiyoli.net/goldsinsweb/home/customer/initMyCenter.html&response_type=code&scope=snsapi_base#wechat_redirect";
		personCenter.setType("view");
		personCenter.setUrl(personCenterViewUrl);

		
		ComplexButton meButton = new ComplexButton();
		meButton.setName("我的");
		meButton.setSub_button(new Button[] {personCenter});
		
		
		Menu menu = new Menu();
		menu.setButton(new Button[] { exclusiveService,imSharedButton, meButton });
		
		
		return JsonUtils.toJson(menu);
	}
	
	private WxMpInMemoryConfigStorage getConfig(){
		WxMpInMemoryConfigStorage config = new WxMpInMemoryConfigStorage();
//		config.setAppId("wx8a0b70c531c68f29"); // 设置微信公众号的appid
//		config.setSecret("294d5f4974ac6aea3d2b16bbac57f855"); // 设置微信公众号的app corpSecret
		config.setAppId("wxbd722b3620a78c59"); // 设置微信公众号的appid
		config.setSecret("d12c686a7c89fa3c43a6c9653f2694b2"); 
		config.setToken(""); // 设置微信公众号的token
		config.setAesKey(""); // 设置微信公众号的EncodingAESKey
		
		return config;
	}
}